define(function (require, exports, module) {
    var myPub = require('./public');
    var SumEvent = require('./sum');
    var GoodsSizeEvent = require('./goodsSize_selet');

    // 曝光可视区域元素
    var visualArea = require('./visualAreaInfo');

    var oWindow = $(window);
    var oWrap = $('.js_wrap');

    var oHeader = $('.js_headerBox');                       // 头部
    var oFooter = $('.js_footer');                          // 底部
    var oContain = $('.js_contain');						// 主体
    var oEmptyCar = $('.js_emptyCar');						// 购物车为空

    var oStoreEditBtn = $('.js_storeEdit');         		// 编辑按钮

    var oAllseletBtn = $('.js_btnAllselet');                // 全部选按钮
    var oAllCheck = oAllseletBtn.find('.js_checkBoxArea');  // 全选选框

    var oSumPrice = $('.js_sumPrice');                      // 总价格
    var nOrderNum = $('.js_orderNum');                      // 订单数量
    var oBtnConfirm = $('.js_btnConfirm');                  // 结算按钮
    var oBtnAllDel = $('.js_btnAllDel');                    // 删除按钮

    var oScrollPage = $('.js_scrollPage');                  // 滚动页面
    var oShopCarGoods = $('.js_shopCarGoods');

    var oTaxSum = $('.js_taxSum');                          // 总的税费
    var oTaxDelCar = $('.js_taxDelCar');                    // 税费区域
    var oTaxAll = $('.js_taxAll');                          // 计算总的税费区域

    var oSideBox = $('.js_sideBox');		                // 侧边按钮框
    var oGoTop = $('.js_goTop');                            // 回到顶部

    var oGlobalType = $('.js_globalType');                  // 结算的商品既有cc2.0的还有普通商品就要显示的弹窗
    var oGoodsSplitSum = $('.js_goodsSplitSum');            // 选择按钮区域
    var oOverSeaNo = $('.js_overSeaNo');                    // 海外直邮商品个数
    var oOverSeaPrice = $('.js_overSeaPrice');              // 海外直邮商品总价
    var oHomeNo = $('.js_homeNo');                          // 国内商品个数
    var oHomePrice = $('.js_homePrice');                    // 国内商品总计
    var oGoodsSplitReturn = $('.js_goodsSplitReturn');      // 弹窗的返回按钮
    var oGoodsSplitNext = $('.js_goodsSplitNext');          // 弹窗的结算按钮
    var nCcGoodsIdCount = '';                               // cc2.0商品id集合
    var nComGoodsIdCount = '';                              // 普通商品的id集合

    var oContainScroll = new myPub.ScrollBar();             // 导航滚动条
    var oSideslipEven = new myPub.HammerEvent();
    var lazLoading = new myPub.lazLoadingImg();

    var oGoods_showTwo = $('.js_goods_showTwo ');
    var oSegmentation = $('.js_segmentation');          // 猜你喜欢标题
    var oLikeGoods = $('.js_likeGoods');                // 猜你喜欢区域
    var oNoMoregBtn = $('.js_noMoregBtn');              // 没有更多了按钮
    var oLoadingBtn = $('.js_loadingBtn');              // 加载中按钮
    var oGoodsList = $('.js_addGoods');                 // 商品列表
    // var oShopCarStore = $('.js_shopCarStore');          // 购物车页面商家入口
    // var guessLikeUrl = '/shop/goods/guessLike';         // 猜你喜欢商品列表地址
    var guessLikeUrl = '/m/g/1.0/group/listGoodsByName';       //猜你喜欢 最新 商品列表地址
    var storeDetailUrl = '/m/g/supplier/1.0/isOverSeaSupplier';// 判斷是否海外商家

    var resizeTimer = null;

    // 获取产品数据的路径
    var goodsDateUrl = '/shop/cartItem/getCartItems';

    var oHeaderHeight = 0;
    var oPullDownHeight = 48;
    if (oHeader.length > 0) {
        oPullDownHeight = oHeaderHeight = oHeader.outerHeight(true)
    }


    // 回到过顶部
    oGoTop.hammer().on('tap', function () {
        oContainScroll.ScrollTo(0, 0, 250, function () {
            oSideBox.stop().animate({'right': '-3.5rem'}, 300);
        });
        myPub.HamstopPropaga();
    });


    // 税费是0就不显示税费区域
    function toggleTax(){
        var ntaxPrice = oTaxSum.text()*1;
        if(ntaxPrice == 0){
            oTaxAll.hide()
        }else{
            oTaxAll.show()
        }
    }

    oTaxDelCar.each(function (index,el) {
        var ntaxrate = $(el).attr('taxrate')*1;
        var nquality = $(el).attr('quality')*1;
        $(el).html((ntaxrate*nquality).toFixed(2));
        toggleTax();
    });

    module.exports = {
        init: function (data, names) {
            var addImgTime = null;
            shopCar.init(true);
            shopCar.initEvent();
            shopCar.ScrollPage();
            shopCar.goToStoreEvent();


            addMore.addAjax(addMore.start, addMore.limit,true,function () {
                clearTimeout(addImgTime);
                addImgTime = setTimeout(function () {
                    shopCar.scrollInit();
                },250);
            });


            // 页面尺寸修改
            oWindow.on('resize', function () {
                if (resizeTimer) {
                    clearTimeout(resizeTimer)
                }
                resizeTimer = setTimeout(function () {
                    shopCar.init(true);
                }, 400);

            });

            // 统计曝光数据
            ddjAction.viewGoods( oGoodsList );
        }
    };


    var shopCar = {
        // 初始化
        init: function (off) {
            var _this = this;
            if (off) {
                oContain.css({
                    'padding-top': 0,
                    'padding-bottom': 0,
                    'top': oHeaderHeight,
                    'bottom': oFooter.outerHeight(true)
                });

                myPub.SetImgHeight(oGoods_showTwo);
            }


            _this.checkShopCarNum();
            lazLoading.AddLazLoadingImg(oScrollPage[0]);
            shopCar.scrollInit();



        },

        // 初始化事件
        initEvent: function () {
            var _this = this;
            var oCheckBox = $('.js_checkBox');          			// 单选按钮
            var oGrayBox = $('.js_grayBox');                        // 已下架按钮
            var oStoreOwner = $('.js_storeOwner');					// 店家名称
            var oDelBtn = $('.js_btnDel');                  		// 单个删除按钮

            shopCar.checkAllSelet();
            // 单选选中和取消
            oCheckBox.hammer().off('tap');
            oCheckBox.hammer().on('tap', function () {
                var $this = $(this);
                _this.seletedOne($this);
                myPub.HamstopPropaga();
            });

            // 选中已下架按钮
           /* oGrayBox.hammer().off('tap');
            oGrayBox.hammer().on('tap', function () {
                var $this = $(this);
                // _this.seletedOne($this);
                // _this.graySelectAll($this);
                // myPub.TipLayer('该商品已下架');
                myPub.HamstopPropaga();
            });*/

            // 店家全选 店名
            oStoreOwner.hammer().off('tap');
            oStoreOwner.hammer().on('tap', function () {
                var $this = $(this);
                _this.seletedAllStore($this)
                myPub.HamstopPropaga();
            });

            // 全选
            oAllseletBtn.hammer().off('tap');
            oAllseletBtn.hammer().on('tap', function () {
                _this.seletedAll();
                myPub.HamstopPropaga();
            });

            // 编辑 act_showSeletSize
            oStoreEditBtn.hammer().off('tap');
            oStoreEditBtn.hammer().on('tap', function () {
                var $this = $(this);
                var oGaryBox = $('.js_grayBox');            // 下架商品
                var oGrayLi = oGaryBox.parents('li');       // 下架商品的li;

                if ($this.hasClass('on')) {
                    var oCurrentGaryBox = $('.js_currentGaryBox');
                    $this.removeClass('on').text('编辑');
                    oShopCarGoods.find('li').removeClass('act_showSeletSize');
                    oBtnConfirm.show();
                    oBtnAllDel.hide();
                    oGoods_showTwo.show();
                    // 编辑完成把下架商品的置灰加上
                    oCurrentGaryBox.removeClass('js_checkBox');
                    oCurrentGaryBox.removeClass('js_currentGaryBox');
                    oCurrentGaryBox.addClass('gray');
                    oCurrentGaryBox.addClass('js_grayBox');
                    _this.initEvent();

                }
                else {
                    $this.addClass('on').text('完成');
                    oShopCarGoods.find('li').addClass('act_showSeletSize');
                    oBtnConfirm.hide();
                    oBtnAllDel.show();
                    oGoods_showTwo.hide();
                    oContainScroll.ScrollTo(0, 0, 250);
                    // 把下架商品的置灰去掉
                    oGrayLi.removeClass('act_showSeletSize');
                    oGaryBox.removeClass('gray');
                    oGaryBox.removeClass('js_grayBox');
                    oGaryBox.addClass('js_checkBox');
                    oGaryBox.addClass('js_currentGaryBox');
                    _this.initEvent();
                }

                oContainScroll.ReScroll();
                myPub.HamstopPropaga();

            });

            // 单个删除
            oDelBtn.hammer().off('tap');
            oDelBtn.hammer().on('tap', function () {
                var $this = $(this);
                _this.deleteOne($this);
                myPub.HamstopPropaga();
            });

            // 全部删除
            oBtnAllDel.hammer().off('tap');
            oBtnAllDel.hammer().on('tap', function () {
                var $this = $(this);
                _this.deleteAll($this, function () {
                    oBtnConfirm.show();
                    oBtnAllDel.hide();
                    oStoreEditBtn.removeClass('on').text('编辑');
                    oGoods_showTwo.show();
                    shopCar.checkAllSelet();
                });

                myPub.HamstopPropaga();

            });

        },

        // 检测是否空的购物车
        checkShopCarNum: function () {
            var _this = this;
            var oCheckBox = $('.js_checkBox');
            var oCarListHead = $('.js_carListHead');        		//店家
            var oCarList = $('.js_carList');                		//全部宝贝
            var oGrayBox = $('.js_grayBox');                        // 下架商品

            oCheckBox.removeClass('active');
            if (oShopCarGoods.find('li').length < 1) {
                oEmptyCar.show();
                oShopCarGoods.hide();
            }
            else {
                oEmptyCar.hide();
                var index = null;         // 有正常商品的商家的下标
                // console.log('bbb',oCarList);
                // 全部是已下架商品的商家选中置灰
                oCarList.each(function (index, el) {
                    // console.log('aaaa'+index, el);
                    var _grayBoxNum = $(el).find('.js_grayBox').length;
                    var _liNum = $(el).find('li').length;
                    var oStoreOwner = oCarListHead.eq(index).find('.js_storeOwner');      // 商家全选
                    // console.log(index, oStoreOwner);
                    if(_grayBoxNum == _liNum){
                        oStoreOwner.find('.js_checkBox').addClass('gray');
                        oStoreOwner.find('.js_checkBox').addClass('js_grayBox');
                        oStoreOwner.find('.js_checkBox').removeClass('js_checkBox');
                    }
                });

                // 全选按钮是否置灰
                _this.selectAllGray();

                // 找到第一个有正常商品的商家
                for(var i = 0; i < oCarList.length; i++){
                    if(oCarList.eq(i).find('.js_checkBox').length > 0){
                        index = i;
                        break;
                    }
                }
                // console.log('ccc',index);

                if(index != null){
                    //默认第一个产品选中
                    if (oCarList.eq(index).find('.js_checkBox').length === 1) {
                        oCarListHead.eq(index).find('.js_checkBox').addClass('active');
                    }
                    oCarList.eq(index).find('.js_checkBox').eq(0).addClass('active');

                    oBtnAllDel.addClass('active');
                }

                /*if (oCarList.eq(0).find('.js_checkBox').length === 1) {
                    oCarListHead.eq(0).find('.js_checkBox').addClass('active');
                }
                oCarList.eq(0).find('.js_checkBox').eq(0).addClass('active');*/

                _this.checkPrice();
            }
        },

        // 全选按钮是否置灰
        selectAllGray: function(){
            var _this = this;
            var oCheckBox = $('.js_checkBox');
            var oGrayBox = $('.js_grayBox');                        // 下架商品
            if(oGrayBox && oCheckBox.length <= 0 && oGrayBox.length > 0) {
                oAllCheck.addClass('gray');
                oBtnAllDel.addClass('active');
                return
            }else{
                oAllCheck.removeClass('gray');
            }
        },

        // 初始化 滚动 和 侧滑
        scrollInit: function () {
            //添加滚动
            if (oContainScroll.obj === undefined) {
                oContainScroll.AddScroll(oContain[0], {
                    id: 'wrapScroll',
                });

                //添加下拉
                shopCarAjax.pullDown();
            }
            else {
                oContainScroll.ReScroll();
            }
            //添加侧滑
            shopCar.sideslip();

        },

        // 检测是否全选
        checkAllSelet: function () {
            var oCarListHead = $('.js_carListHead');        		//店家
            var _actNum = oCarListHead.find('.js_checkBox.active').length;
            var _checkNum = oCarListHead.find('.js_checkBox').length;

            // 商家选中个数为零
            if(_actNum === 0) {
                oAllCheck.removeClass('active');
                return
            }

            //判断全部产品是否选中
            if (_actNum >= _checkNum) {
                oAllCheck.addClass('active');
            }
            else {
                oAllCheck.removeClass('active');
            }
        },

        // 检测是价格
        checkPrice: function () {
            var oCarList = $('.js_carList');
            //重新计算一下商品总数
            var orderNum = oCarList.find('.js_checkBox.active').length;
            nOrderNum.text(orderNum);

            // 重置合计税收价格
            myPub.ShopSumPrice(oCarList.find('.js_checkBox'), '.js_carListArea', '.js_taxDelCar', oTaxSum);

            //重置合计价格数据
            myPub.ShopSumPrice(oCarList.find('.js_checkBox'), '.js_carListArea', '.js_goodsPrice', oSumPrice);

            toggleTax();
        },

        // 单选
        seletedOne: function (obj) {
            var _this = this;
            var _parents = obj.parents('.js_carList');
            if (obj.hasClass('active')) {
                obj.removeClass('active')
                _parents.siblings('.js_carListHead').find('.js_checkBox').removeClass('active');
                oAllCheck.removeClass('active');


                if (oShopCarGoods.find('.js_checkBox.active').length < 1) {
                    oBtnAllDel.removeClass('active');
                }

            }
            else {
                obj.addClass('active');
                // 店家全选判断
                var _ActiveNum = _parents.find('.js_checkBox.active').length;
                var _CheckBoxNum = _parents.find('.js_checkBox').length;

                //判断当前店家产品是否选中
                if (_ActiveNum >= _CheckBoxNum) {
                    _parents.siblings('.js_carListHead').find('.js_checkBox').addClass('active');
                    _this.checkAllSelet();
                }

                oBtnAllDel.addClass('active');
            }

            _this.checkPrice();
        },

        // 全选
        seletedAll: function () {
            var _this = this;
            var oCheckBox = $('.js_checkBox');          			//单选按钮
            var oGrayBox = $('.js_grayBox');                        // 下架商品

            // 购物车无正常商品
            if(oCheckBox.length <= 0){
                if(oGrayBox && oGrayBox.length > 0){
                    // myPub.TipLayer('您所选的商品已下架');
                    oBtnAllDel.addClass('active');
                    return
                }else{
                    myPub.TipLayer('您的购物车是空的哦！');
                    oAllCheck.removeClass('active');
                    oBtnAllDel.removeClass('active');
                    oSumPrice.text('0.00');
                    return
                }

            }else{
                // 购物车有正常商品
                if (oAllCheck.hasClass('active')) {
                    oAllCheck.removeClass('active');
                    oCheckBox.removeClass('active');
                    oBtnAllDel.removeClass('active');
                    oSumPrice.text('0.00');
                }
                else {
                    oAllCheck.addClass('active');
                    oCheckBox.addClass('active');
                    oBtnAllDel.addClass('active');
                    _this.checkPrice();
                }
            }
        },

        // 商家全选
        seletedAllStore: function (obj) {
            var _this = this;
            var _checBox = obj.find('.js_checkBox');
            var _parents = obj.parents('.js_carListHead');
            if (_checBox.hasClass('active')) {
                _checBox.removeClass('active');
                _parents.siblings('.js_carList').find('.js_checkBox').removeClass('active');
                oAllCheck.removeClass('active');

                if (oShopCarGoods.find('.js_checkBox.active').length < 1) {
                    oBtnAllDel.removeClass('active');
                }
            }
            else {
                _checBox.addClass('active');
                _parents.siblings('.js_carList').find('.js_checkBox').addClass('active');
                oBtnAllDel.addClass('active');
                _this.checkAllSelet()
            }
            _this.checkPrice()
        },

        // 删除单个
        deleteOne: function (obj) {
            var _this = this;
            var _cont = '<p class="delTipP">确定删除该商品?</p><span class="delTipSpan">删除后不可恢复哦</span>';
            var $this = obj;
            myPub.askLayer(_cont, function () {
                var cartId = $this.parents('li').attr("cartItemId");

                G_JSON_POST("/shop/cartItem/removeCart/" + cartId, null, function (data) {
                    if (data.status == "success") {

                        var _carList = $this.parents('.js_carList');
                        var oStoreOwner = _carList.siblings('.js_carListHead').find('.js_storeOwner');

                        //判断是否只有1个产品
                        if ($this.parents('.js_shopCarGoods').find('li').length == 1) {
                            $this.parents('.js_carListBox').remove();
                            oEmptyCar.show();
                            oShopCarGoods.hide();
                            oGoods_showTwo.show();
                        }
                        //删除只有1个商品的店家
                        else if (_carList.find('li').length == 1) {
                            $this.parents('.js_carListBox').remove();
                        }
                        //删除其中一个产品
                        else {

                            var _carListHeadCheck = _carList.siblings('.js_carListHead').find('.js_checkBox');
                            $this.parents('li').remove();

                            //删除后是否店家全选
                            _carList.find('li').length == _carList.find('.js_checkBox.active').length ? _carListHeadCheck.addClass('active') : _carListHeadCheck.removeClass('active');

                            // 删除后判断是否全部已下架商品
                            if(_carList.find('.js_grayBox') && _carList.find('li').length == _carList.find('.js_grayBox').length){
                                oStoreOwner.find('.js_checkBox').addClass('gray');
                                oStoreOwner.find('.js_checkBox').addClass('js_grayBox');
                                oStoreOwner.find('.js_checkBox').removeClass('js_checkBox');
                            }
                        }


                        //判断是否高亮选中删除按钮
                        if (oShopCarGoods.find('.js_checkBox.active').length < 1) {
                            oBtnAllDel.removeClass('active');
                        }
                        else {
                            oBtnAllDel.addClass('active');
                        }

                        // 全选按钮是否置灰
                        _this.selectAllGray();

                        _this.checkAllSelet();
                        _this.checkPrice();
                        _this.scrollInit();

                        myPub.LayerCloseAll();
                        myPub.TipLayer('删除成功！');
                    }
                    else {
                        myPub.TipLayer(data.message);
                    }
                });

            }, function () {
                //去除样式

            });

        },

        // 删除全部
        deleteAll: function (obj, fn) {
            var _this = this;
            var _cont = '<p class="delTipP">确定删除该商品?</p><span class="delTipSpan">删除后不可恢复哦</span>';
            var $this = obj;
            var cartIds = [];
            if ($this.hasClass('active')) {
                //可点击
                myPub.askLayer(_cont, function () {
                    var oCarListBox = oShopCarGoods.find('.js_carListBox');
                    if(oCarListBox.find('.js_checkBox.active').length == 0) {
                        myPub.LayerCloseAll();
                        myPub.TipLayer('您的购物车是空的哦！');
                        return;
                    }
                    oCarListBox.find('.js_checkBox.active').each(function (index, obj) {

                        if ($(this).hasClass('VBox')) {
                            cartIds.push(parseInt($(this).parents('li').attr("cartItemId")));
                        }

                    });
                    // console.log(cartIds);
                    G_JSON_POST("/shop/cartItem/removeCarts", {"cartIds": cartIds}, function (data) {
                        if (data.status = "success") {
                            oShopCarGoods.find('.js_checkBox.active').parents('li').remove();
                            oCarListBox.each(function (i) {
                                if (oCarListBox.eq(i).find('.js_carList .js_checkBox').length < 1) {
                                    oCarListBox.eq(i).remove();
                                    oSumPrice.text(0);
                                    nOrderNum.text(0);
                                }
                            });

                            if ($('.js_carListBox').length == 0) {
                                oEmptyCar.show();
                                oShopCarGoods.hide();
                                if (fn) fn();
                            }

                            $this.removeClass('active');

                            _this.checkAllSelet();
                            _this.checkPrice();
                            _this.scrollInit();
                            myPub.LayerCloseAll();
                            myPub.TipLayer('删除成功！');
                        }
                    });

                }, function () {

                }, 'no')
            }
            else {
                //不可点击
                myPub.TipLayer('没有选中要删除的宝贝！')
            }

        },

        // 侧滑
        sideslip: function () {
            oShopCarGoods.find('li').each(function (i) {
                oSideslipEven.addHamEvent(oShopCarGoods.find('li')[i], 'panleft', function () {
                    oShopCarGoods.find('li').removeClass('act_showDel').eq(i).addClass('act_showDel')
                    myPub.HamstopPropaga();
                });

                oSideslipEven.addHamEvent(oShopCarGoods.find('li')[i], 'panright', function () {
                    oShopCarGoods.find('li').removeClass('act_showDel');
                    myPub.HamstopPropaga();
                });

            });
        },

        // 滚动页面
        ScrollPage: function () {
            var _this = this;
            var scrollTime = null;
            var addLoadingTime = null;
            var minScrHeight = 200;

            oContainScroll.ScrollIng(function () {

                var _scrollTop = -oContainScroll.obj.y;
                var _scrollHeight = oContainScroll.obj.scrollerHeight;
                var _scrollPageHeight = oContainScroll.obj.wrapperHeight;
                clearTimeout(scrollTime);
                scrollTime = setTimeout(function () {
                    _this.ShowGoTop(_scrollTop);
                    // 统计曝光数据
                    ddjAction.viewGoods( oGoodsList );

                    if (_scrollHeight - _scrollTop - _scrollPageHeight < minScrHeight) {
                        // 滚动加载产品
                        // 设置翻页到最后一页 返回
                        if(!addMore.bLoadOff) {
                            addMore.dataJson = null;
                            return;
                        }

                        // 滚动底部页数增加 起始数据等于上次结束数据  新的结束等于页数*页码数
                        addMore.start = addMore.limit*addMore.pagearr;
                        addMore.pagearr++;
                        addMore.addAjax(addMore.start, addMore.limit, false,function () {
                            clearTimeout(addLoadingTime);
                            addLoadingTime = setTimeout(function () {
                                shopCar.scrollInit();
                            },250);
                        });
                    }
                }, 800);

            });
        },

        // 显示回到顶部按钮
        ShowGoTop: function (scrollTop) {
            scrollTop > 150 ? oSideBox.stop().animate({'right': 0}, 300) : oSideBox.stop().animate({'right': '-3.5rem'}, 300);
        },

        // 点击进入店铺详情页面要判断是否是海外店铺
        goToStoreEvent: function(){
            var _this = this;
            $('.js_goToStore').on('click',function () {
                var supplierId = $(this).attr('data-supplierId');
                _this.goToStoreDetail(supplierId);
            })
        },

        // 判断是进入海外店铺还是进入普通店铺的接口
        goToStoreDetail: function (supplierId) {
            var _this = this;
            G_JSON_POST(storeDetailUrl,{'supplierId':supplierId},function (data) {
                var _data = data.data;
                var _ret = data.ret;
                // console.log('data',_data,_ret);
                if(_ret.code=='0'){
                    if(_data){
                        // 海外馆商家
                        window.location.href =  BASE_URL +'/h/store/storehome?supplierId='+ supplierId ;
                    }
                    else{
                        // 普通商家
                        window.location.href =  BASE_URL +'/h/store/normalStore/'+ supplierId ;
                    }
                }
                else{
                    // 如果请求不到就跳转普通商家
                    window.location.href =  BASE_URL +'/h/store/normalStore/'+ supplierId ;
                }
            })
        }

    };

    var addMore = {
        limit:20,               // 每次加载数据数目
        getData:[],             // 获取接口返回的数据
        pagearr:1,              // 当前页码数
        start:0,                // 开始数据
        bLoadOff:true,          // 加载开关
        loadNo : 0,             // 加载次数
        // 获取数据
        addAjax:function (start,limit,bAddLoad,fn) {
            var _this =this;
            var sendNo = '';
            if(bAddLoad){
                sendNo = {'start': start, 'limit': limit,'isFirst':1, groupName: 'H5_猜你喜欢'}
            }else{
                sendNo = {'start': start, 'limit': limit, groupName: 'H5_猜你喜欢'}
            }
            if(_this.loadNo < 5){
                G_JSON_GET(guessLikeUrl,sendNo,function (data) {
                    var _ret = data.ret;
                    if (_ret.code != '0') return;
                    _this.loadNo ++;
                    _this.getData = data.data;
                    // 没有数据
                    if(_this.getData.length < 0 && _this.pagearr < 2){
                        oNoMoregBtn.show();
                        oLoadingBtn.hide();
                        _this.bLoadOff = false;
                        oSegmentation.hide();
                        oLikeGoods.hide();
                        shopCar.scrollInit();
                        return
                    }
                    if(_this.pagearr >= 1){
                        if(_this.getData.length == 0){
                            oNoMoregBtn.show();
                            oLoadingBtn.hide();
                            _this.bLoadOff = false;
                            shopCar.scrollInit();
                            return
                        }
                    }
                    // 拼接页面
                    shopCarAjax.addHtml(_this.getData);

                    if(_this.getData.length < _this.limit){
                        oNoMoregBtn.show();
                        oLoadingBtn.hide();
                        _this.bLoadOff = false;
                    }
                    data = null;
                    if(fn)fn();
                },function () {},function () {})
            }else{
                oNoMoregBtn.show();
                oLoadingBtn.hide();
                _this.bLoadOff = false;
                shopCar.scrollInit();
            }

        }
    };

    var shopCarAjax = {

        // 下拉刷新
        pullDown: function () {
            var _this = this;
            var _textTip = [
                '<i class="textPull">轻轻下拉刷新，查看新加产品</i>',

                '<i class="textRelease HBox BoxCenter">' +
                '   <figure class="ddjLogoImg"><img src="' + BASE_URL + '/static_v4/image/iconPic/tip_ddj.png" alt=""></figure>' +
                '   <em class="ddjText">' +
                '       <span class="ddjText_tip">有担当， 更爱家 </span>' +
                '       <span>松手更新...</span>' +
                '   </em>' +
                '</i>',

                '<i class="textLoading HBox BoxCenter">' +
                '   <figure class="ddjLogoImg"><img src="' + BASE_URL + '/static_v4/image/iconPic/tip_ddj.png" alt=""></figure>' +
                '   <em class="ddjText">' +
                '       <span class="ddjText_tip">有担当， 更爱家 </span>' +
                '       <span>更新中...</span>' +
                '   </em>' +
                '</i>'
            ];

            //添加下拉
            oContainScroll.ScrollPullDown({
                pulldownHeight: oPullDownHeight,
                iconArrow: '',
                iconLoading: '',
                iconFinish: '',
                textPull: _textTip[0],
                textRelease: _textTip[1],
                textLoading: _textTip[2],
                textFinish: _textTip[2],
                spinning: false,
                refresh: function (complete) {
                    _this.ShopListAjaxData(function () {
                        lazLoading.DestroyLazLoadingImg();
                        lazLoading.AddLazLoadingImg(oScrollPage[0]);
                        SumEvent.SumPriceEvent();
                        GoodsSizeEvent.GoodsSizeSelet();
                        shopCar.checkAllSelet();
                        complete();
                    });

                }
            });
        },

        // 设置 购物车产品数据
        ShopListAjaxData: function (fn) {
            var html = '';
            G_JSON_POST(goodsDateUrl, {
                // "maxLimit":maxLimit
            }, function (data) {
                // console.log(data.goodsNew.length);
                var dataJson = data.obj;
                if (data.status == "success") {

                    for (var p in dataJson) {
                        var sHtml = '<section class="carListBox js_carListBox">' +
                            shopCarAjax.ShopStoreHtml(dataJson[p]) +
                            shopCarAjax.ShopListHtml(dataJson[p].productList) +
                            '</section>'
                        html += sHtml;
                    }

                    var $html = $(html);

                    oShopCarGoods.empty().prepend($html);
                    // 判断进入哪个店铺页面
                    shopCar.goToStoreEvent();
                    oEmptyCar.hide();
                    oShopCarGoods.show();

                    data = null;
                    dataJson = null;

                } else {
                    oEmptyCar.show();
                    oShopCarGoods.hide();
                }

            }, function () {
                // start
            }, function () {
                // end
                shopCar.init(false);
                shopCar.initEvent();
                if (fn) fn()
            });

        },

        // 购物车产品信息
        ShopListHtml: function (productList) {
            var _this = this;
            var sHtmlBox = '';
            var sHtml = '';
            var taxShtml = '';
            var isShelvesHtml = '';         // 是否是下架商品
            var priceHtml = '';             // 价格显示区域
            var GoodTypesHtml = '';         // cc2.0商品标识或BC商品标识
            // if()act_fixedSize act_moreSize

            for (var p in productList) {
                if(productList[p].calGlobalFee && productList[p].calGlobalFee!=undefined && productList[p].calGlobalFee!=''){
                    var ntaxPrice = ((productList[p].calGlobalFee)*(productList[p].quantity)).toFixed(2)*1;
                    taxShtml = ' <div class="shopCarTax js_taxDelAreaCar">' +
                        '              <span>预估税费：￥</span>' +
                        '              <span class="js_taxDelCar" taxrate="'+productList[p].calGlobalFee+'" quality="'+productList[p].quantity+'">'+ntaxPrice+'</span>' +
                        '         </div>';
                }else{
                    taxShtml = '';
                }

                isShelvesHtml = '';
                priceHtml = '';
                // shelves: 0,已上架，1：已售罄，2：已下架
                if(productList[p].shelves == 1){
                    isShelvesHtml =
                        '<span class="goodsCartNull goodsSellOut"></span>'+
                        '<div class="checkBoxArea js_grayBox VBox BoxCenter gray" cartItemId="' + productList[p].cartItemId + '" globalOrderType="'+productList[p].crossBorderPattern+'">';
                    priceHtml = '<i class="goodsPrice">￥</i>' +
                        '<span class="goodsPrice js_goodsPrice" pprice="' + productList[p].salePrice + '">' + productList[p].totalPrice.toFixed(2) + '</span>';
                }else if(productList[p].shelves == 2){
                    isShelvesHtml =
                        '<span class="goodsCartNull goodsShelves"></span>' +
                        '<div class="checkBoxArea js_grayBox VBox BoxCenter gray" cartItemId="' + productList[p].cartItemId + '" globalOrderType="'+productList[p].crossBorderPattern+'">';
                    priceHtml = '<span class="goodsPrice">暂无报价</span>';
                }else{
                    isShelvesHtml = '<div class="checkBoxArea js_checkBox VBox BoxCenter " cartItemId="' + productList[p].cartItemId + '" globalOrderType="'+productList[p].crossBorderPattern+'">';
                    priceHtml = '<i class="goodsPrice">￥</i>' +
                        '<span class="goodsPrice js_goodsPrice" pprice="' + productList[p].salePrice + '">' + productList[p].totalPrice.toFixed(2) + '</span>';

                }

                // cc2.0商品标识
                GoodTypesHtml = '';
                if(productList[p].crossBorderPattern == 4){
                    GoodTypesHtml =
                        '<div class="HBox goodsSplitMark">' +
                        '   <div class="goodsSplitMarkIcon">' +
                        '       <img src="'+BASE_URL+'/static_v4/image/iconImg/icon_globalCart.png" alt="">' +
                        '   </div>' +
                        '   <div class="goodsSplitMarkTxt">个人海外直邮商品</div>' +
                        '</div>';
                }else if(productList[p].crossBorderPattern == 3){
                    GoodTypesHtml =
                        '<div class="HBox goodsSplitMark personalBc">' +
                        '   <div class="goodsSplitMarkIcon">' +
                        '       <img src="'+BASE_URL+'/static_v4/image/iconImg/icon_globalBC.png" alt="">' +
                        '   </div>' +
                        '   <div class="goodsSplitMarkTxt">海外直邮商品</div>' +
                        '</div>';
                }

                sHtml +=
                    '<li cartItemId="' + productList[p].cartItemId + '" productId = "' + productList[p].id + '">' +
                    '   <div class="sideslipScroll">' +
                    GoodTypesHtml+
                    // '<div class="tipInfoBox HBox BoxCenter">'+
                    // '<em>满减</em>'+
                    // '<span class="Bflex1">购满2件，总价可打8.00折</span>'+
                    // '<a href="" class="color_red">'+
                    // '<i>去凑单</i>'+
                    // '<i class="icon-chevron-right"></i>'+
                    // '</a>'+
                    // '</div>'+

                    '       <section class="HBox BoxCenter carListArea js_carListArea">' +
                    isShelvesHtml+
                    // '           <div class="checkBoxArea js_checkBox VBox BoxCenter " cartItemId="' + productList[p].cartItemId + '">' +
                    '               <span class="checkBox icon-check"></span>' +
                    '           </div>' +

                    '           <div class="HBox Bflex1" >' +
                    '               <figure>' +
                    '                   <a href="' + BASE_URL + '/h/goodspay/goodsView/' + productList[p].goodsSn + '"><img class="js_lazyImg" data-echo="' + HTTP_IMAGE_URL + '' + productList[p].goodsImageUrl + smallImgArg200 + '" src="' + BASE_URL + '/static_v4/image/loadImg.jpg"></a>' +
                    '                   <i class="tip-city"></i>' +
                    '               </figure>' +
                    '               <aside class="priceArea VBox Bflex1">' +
                    '                   <div class="outProvince VBox Bflex1">'+
                    '                   <div class="Bflex1 priceArea_name">' +
                    '                       <h4><a href="' + BASE_URL + '/h/goodspay/goodsView/' + productList[p].goodsSn + '">' + productList[p].goodsName + '</a></h4>' +
                    '                       <p class="smallFont_tip goodsSize js_goodsSize act_moreSize">' +
                    '                           <span>规格:已选择</span>' +
                    '                           <span class="js_sizeShow">' + productList[p].spcName + '</span>' +
                    '                           <span class="iconStyle icon-href-down"></span>' +
                    '                       </p>' +
                    '                   </div>' +
                    '                   <div class="priceArea_price">' +
                    '                       <p class="HBox priceAreaBox">' +
                                                priceHtml+
                    '                       </p>' +
                    '                   </div>' +
                    '                       <div class="amountBox HBox js_amountBox BoxCenter ">' +
                    '                           <div class="js_grayGoods cartGrayGoods" ></div>'+
                    '                           <button class="numBtn js_handBtn active incart " cartItemId="' + productList[p].cartItemId + '" type="button">-</button>' +
                    '                           <input class="sumNum js_sumNum" cartItemId="' + productList[p].cartItemId + '" type="number" name="" id="" value="' + productList[p].quantity + '"  />' +
                    '                           <button class="numBtn js_handBtn incart" cartItemId="' + productList[p].cartItemId + '" type="button">+</button>' +
                    '                       </div>' +
                    '                   </div>' +
                    taxShtml+
                    '               </aside>' +
                    '           </div>' +
                    '           <div class="jsMinCount" style="display: none" minCount="' + productList[p].minCount + '"></div>' +

                    '       </section>' +
                    '   </div>' +
                    '   <aside class="btnDel HBox BoxCenter js_btnDel">' +
                    '       <p class="Bflex1">删除</p>' +
                    '   </aside>' +
                    '</li>';
            }

            sHtmlBox =
                '<section class="carList js_carList goods_showChangeBox js_goods_showOne ">' +
                '   <div class="goods_showChange"><ul class="goodsList">' + sHtml + '</ul></div>' +
                '</section>';
            return sHtmlBox;

        },

        // 购物车商家信息
        ShopStoreHtml: function (data) {
            // console.log(data);
            var _this = this;
            var sHtml = '<section class="carListHead HBox BoxCenter js_carListHead">' +
                '<div class="storeOwner js_storeOwner Bflex1 HBox BoxCenter">' +
                '<div class="checkBoxArea js_checkBox">' +
                '<span class="checkBox icon-check"></span>' +
                '</div>' +
                '<div class="storeName Bflex1">' +
                '<span class="iconStyle icon_store"></span><span>' + data.nickName + '</span>' +
                '</div>' +
                '</div>' +
                // '<a href="' + BASE_URL + '/h/store/normalStore/' + data.id + '" class="iconStyle icon-href-right"></a>' +
                '<a data-supplierId="'+data.id+'" class="iconStyle icon-href-right js_goToStore"></a>' +
                '</section>';
            return sHtml;
        },

        // 拼接数据
        addHtml:function (data) {
            var thtml = '';
            for(var i = 0;i < data.length;i++){
                var dataItem = data[i];
                var quanpeiHtml = '';
                //如果有全赔图标则显示
                if(dataItem.firstGueeImagePath) {
                    quanpeiHtml = '<div class="quanpei"><img src="https://img.sfddj.com/miniappImg/public/goodsInfo/'+dataItem.firstGueeImagePath+'" alt="" /></div>'
                }
                thtml +=
                    '<li>'+
                    '   <a class="BoxSelf" href="'+BASE_URL+'/h/goodspay/goodsView/'+dataItem.goodsSn+'" requestid="'+dataItem.requestId+'"  goodsid="'+ dataItem.id +'">'+
                    '       <figure>'+
                    '           <img class="js_lazyImg" data-echo="'+HTTP_IMAGE_URL+ dataItem.goodsDefaultImage + smallImgArg200+'" src="'+BASE_URL+'/static_v4/image/loadImg.jpg">'+
                    quanpeiHtml+
                    '       </figure>'+
                    '       <aside class="priceArea VBox Bflex1">'+
                    '           <div class="Bflex1 priceArea_name">'+
                    '               <h4>'+dataItem.goodsName+'</h4>'+
                    '               <p class="smallFont_tip">'+dataItem.goodsTitle+'</p>'+
                    '           </div>'+
                    '           <div class="priceArea_price">'+
                    '               <p class="HBox priceAreaBox">'+
                    '                   <span class="goodsPrice">￥'+dataItem.salePrice+'</span>'+
                    '               </p>'+
                    '           </div>'+
                    '       </aside>'+
                    '   </a>'+
                    '   <p class="addCar js_addCar" pid="'+dataItem.productId+'"><em class="icon-shopcar_small"></em></p>'+
                    '</li>';
            }
            oGoodsList.append(thtml);
            lazLoading.AddLazLoadingImg(oScrollPage[0]);
        }
    };


    /*// 在页面遍历的商家入口判断进入商家的链接
    if(oShopCarStore && oShopCarStore.length>0){
        $('.js_shopCarStore').on('click',function () {
            var supplierId = $(this).attr('data-supplierId');
            shopCar.goToStoreDetail(supplierId);
        })
    }*/

    // 商品的类型 0 非进口; 1 cc; 2 国内保税仓; 3 bc; 4 cc2.0; 
    var goodsType = {
        event:function () {
            var _this = this;
            // 结算海外还是国内单选
            oGoodsSplitSum.on('click',function (e) {
                var oGoodsSplitChoose = $(this).find('.js_goodsSplitChoose');
                var oSlibGoodsSplitChoose = $(this).siblings('.js_goodsSplitSum').find('.js_goodsSplitChoose');

                if(!oGoodsSplitChoose.hasClass('active')){
                    oGoodsSplitChoose.addClass('active')
                }
                if(oSlibGoodsSplitChoose.hasClass('active')){
                    oSlibGoodsSplitChoose.removeClass('active')
                }
                e.stopPropagation();
                myPub.HamstopPropaga();
            });

            // 返回按钮 隐藏弹窗
            oGoodsSplitReturn.on('click',function (e) {
                oGlobalType.hide();
                e.stopPropagation();
                myPub.HamstopPropaga();
            });

            // 弹窗的结算按钮
            oGoodsSplitNext.on('click',function (e) {
                var oChooseBox = oGoodsSplitSum.find('.js_goodsSplitChoose.active');
                var goodsIdCount = '';
                // 海外直邮商品
                if(oChooseBox.hasClass('js_overSeaBox')){
                    goodsIdCount = nCcGoodsIdCount;
                }
                // 国内商品
                else{
                    goodsIdCount = nComGoodsIdCount;
                }
                $("#cartIds").val(goodsIdCount);
                var action = "/shop/pay/cartItem_confirm?cartIds=" + $("#cartIds").val() + "&goodschannel=" + $("#goodschannel").val()+"&recRequestId="+$("#recRequestId").val()+"&sceneType="+$("#sceneType").val();
                $('#subForm').attr("action", action);
                $('#subForm').submit();

                e.stopPropagation();
                myPub.HamstopPropaga();
            })

        }
    };
    goodsType.event();

    // 结算
    oBtnConfirm.hammer().on('tap', function () {
        var ids = "";
        var bBcType = false;                // bc清关商品
        var bCcType2 = false;               // cc2.0的商品
        var bComType = false;               // 非cc2.0 非bc的商品
        var nCcNo2 = 0;                     // cc2.0商品总个数
        var nCcPrice2 = 0;                  // cc2.0商品总价格
        var nComNo = 0;                     // 普通商品总个数
        var nComPrice = 0;                  // 普通商品总价位

        $('.js_carListArea').find('.js_checkBox.active').each(function () {
            var globalType = $(this).attr('globalOrderType');
            var goodsPrice = $(this).parents('.js_carListArea').find('.js_goodsPrice').text()*1;
            ids += $(this).attr('cartItemId') + ",";
            if(globalType == 3){
                bBcType = true;
            }else if(globalType == 4){
                bCcType2 = true;
                nCcNo2 += 1;
                nCcPrice2 += goodsPrice;
                nCcGoodsIdCount += $(this).attr('cartItemId') + ",";
            }else{
                bComType = true;
                nComNo += 1;
                nComPrice += goodsPrice;
                nComGoodsIdCount += $(this).attr('cartItemId') + ",";
            }
        });
        // console.log('nCcGoodsIdCount',nCcGoodsIdCount,nComGoodsIdCount);
        // console.log('type',bBcType,bCcType2,bComType);
        if (ids == "") {
            myPub.TipLayer("请选择要结算的商品");
            return;
        }
        // bc海外直邮商品不能在购物车购买
        if(bBcType){
            myPub.TipLayer('海外直邮商品，仅支持商详页直接购买！');
            return
        }
        // 如果结算的商品既有cc2.0的 还有普通商品 就要显示弹窗
        if(bCcType2 && bComType){
            oOverSeaNo.text(nCcNo2);
            oOverSeaPrice.text(nCcPrice2.toFixed(2));
            oHomeNo.text(nComNo);
            oHomePrice.text(nComPrice.toFixed(2));
            oGlobalType.show();
            return
        }
        $("#cartIds").val(ids);
        var action = "/shop/pay/cartItem_confirm?cartIds=" + $("#cartIds").val() + "&goodschannel=" + $("#goodschannel").val()+"&recRequestId="+$("#recRequestId").val()+"&sceneType="+$("#sceneType").val();
        $('#subForm').attr("action", action);
        $('#subForm').submit();
    });

    // 用户行为
    var ddjAction = {
        viewData: [],
        viewGoods: function (obj, iNow) {
            // 首页和分类区分
            var ddjActionPositionId = {};

            ddjActionPositionId.positionId = 2;

            // 个人中心 猜你喜欢
            ddjActionPositionId.positionFirst = '购物车';
            ddjActionPositionId.positionSecond = '猜你喜欢';

            // 统计曝光数据
            visualArea.viewEl.showViewEls( obj, function (data, dataJson) {
                ddjhoc.setData(data, 'rec_show', 'add', function () {
                    console.log('ddjhoc.params.rec_show.shopCar', ddjhoc.params);
                    if( ddjhoc.params.length != 0 ) ddjhoc.sendData( ddjhoc.params );

                    console.log('ddjhoc.ddjParams.rec_show.shopCar', ddjhoc.ddjParams);
                    if( ddjhoc.ddjParams.length != 0 ) ddjhoc.sendDDJData( ddjhoc.ddjParams );

                }, dataJson, ddjActionPositionId);
            });
        }
    }


});